<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <cpn></cpn>

      <!-- <cpn>
        <span v-for="item in pLanguages">{{item}}</span>
      </cpn> -->
      <cpn>
        <!-- 目的是获取子组件中的pLanguages -->
        <template slot-scope="slot">
          <!-- <span v-for="item in slot.data">{{item}} - </span> -->
          <!-- 去掉末尾的空格 -->
          <span>{{slot.data.join(' - ')}}</span>
        </template>
      </cpn>
    </div>

    <template id="cpn">
      <div>
        <!-- <ul>
          <li v-for="item in pLanguages">{{item}}</li>
        </ul> -->
        <slot :data="pLanguages">
          <ul>
            <li v-for="item in pLanguages">{{item}}</li>
          </ul>
        </slot>
      </div>
    </template>

    <script src="../js/vue.js"></script>

    <script>
      const app = new Vue({
        el: "#app",
        data: {
          message: "你好",
        },
        components: {
          cpn: {
            template: "#cpn",
            data() {
              return {
                pLanguages: [
                  "JavaScript",
                  "C++",
                  "Java",
                  "Python",
                  "Go",
                  "Swift",
                ],
              };
            },
          },
        },
      });
    </script>
  </body>
</html>
